package com.sundablog.controller.backend.system.upms.filesystem;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.sundablog.result.BaseResult;
import com.sundablog.service.backend.system.upms.filesystem.FilesyStemService;

/**
 * 文件上传控制器类
 * @ClassName:  FilesyStemController   
 * @Description:文件上传控制器类
 * @author: 哒哒 
 * @date:   2018年3月30日 下午1:07:02   
 *     
 * @Copyright: 2018 www.sundablog.com Inc. All rights reserved.
 */
@Controller
@RequestMapping("/Upload")
public class FilesyStemController {

	@Autowired
	private FilesyStemService filesyStemService;
	
	
	/**
	 * layui文件上传
	 * @Title: layuiUpload   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param file
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequestMapping("/layuiUpload")
	@ResponseBody
	public BaseResult layuiUpload(MultipartFile file){
		String url = "";
		try {
			url = filesyStemService.fileUploadLayui(file.getBytes());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String downloadUrl = filesyStemService.getDownloadUrl(url);
		Map<String, String> map = new HashMap<>(100);
		map.put("route", "200");
		map.put("fullPath", url);
		map.put("downloadUrl", downloadUrl);
		return BaseResult.build(200, "", map);
	}
	
}
